package pt.ipleiria.estg.es2.byinvitationonly;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class WhoIsHereActivity extends Activity {

    public static boolean imHere;
    private Menu menu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_who_is_here);

        imHere = MainActivity.imHere;
    }

    private void setImHere(boolean state, MenuItem item) {
        if (!state) {
            imHere = true;
            item.setIcon(R.drawable.ic_action_not_alone);
        } else {
            imHere = false;
            item.setIcon(R.drawable.ic_action_alone);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_who_is_here, menu);
        this.menu = menu;
        setImHere(!imHere, menu.findItem(R.id.action_whoishere_im_here));
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_whoishere_im_here) {
            setImHere(imHere, item);
        }

        return super.onOptionsItemSelected(item);
    }
}
